home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Příklady / 3.Anti-Debugging / Detekce SoftICu / CreateFile / CreateFileDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-07  |  3.0 KB  |  120 lines

  1. // CreateFileDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "CreateFile.h"
  6. #include "CreateFileDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CCreateFileDlg dialog
  16.  
  17. CCreateFileDlg::CCreateFileDlg(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CCreateFileDlg::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CCreateFileDlg)
  21.         // NOTE: the ClassWizard will add member initialization here
  22.     //}}AFX_DATA_INIT
  23.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  24. }
  25.  
  26. void CCreateFileDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(CCreateFileDlg)
  30.         // NOTE: the ClassWizard will add DDX and DDV calls here
  31.     //}}AFX_DATA_MAP
  32. }
  33.  
  34. BEGIN_MESSAGE_MAP(CCreateFileDlg, CDialog)
  35.     //{{AFX_MSG_MAP(CCreateFileDlg)
  36.     ON_WM_PAINT()
  37.     ON_WM_QUERYDRAGICON()
  38.     ON_BN_CLICKED(IDC_OK, OnOk)
  39.     //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CCreateFileDlg message handlers
  44.  
  45. BOOL CCreateFileDlg::OnInitDialog()
  46. {
  47.     CDialog::OnInitDialog();
  48.  
  49.     SetIcon(m_hIcon, TRUE);            // Set big icon
  50.     SetIcon(m_hIcon, FALSE);        // Set small icon
  51.     
  52.     // TODO: Add extra initialization here
  53.     
  54.     return TRUE;  // return TRUE  unless you set the focus to a control
  55. }
  56.  
  57. // If you add a minimize button to your dialog, you will need the code below
  58. //  to draw the icon.  For MFC applications using the document/view model,
  59. //  this is automatically done for you by the framework.
  60.  
  61. void CCreateFileDlg::OnPaint() 
  62. {
  63.     if (IsIconic())
  64.     {
  65.         CPaintDC dc(this); // device context for painting
  66.  
  67.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  68.  
  69.         // Center icon in client rectangle
  70.         int cxIcon = GetSystemMetrics(SM_CXICON);
  71.         int cyIcon = GetSystemMetrics(SM_CYICON);
  72.         CRect rect;
  73.         GetClientRect(&rect);
  74.         int x = (rect.Width() - cxIcon + 1) / 2;
  75.         int y = (rect.Height() - cyIcon + 1) / 2;
  76.  
  77.         // Draw the icon
  78.         dc.DrawIcon(x, y, m_hIcon);
  79.     }
  80.     else
  81.     {
  82.         CDialog::OnPaint();
  83.     }
  84. }
  85.  
  86. HCURSOR CCreateFileDlg::OnQueryDragIcon()
  87. {
  88.     return (HCURSOR) m_hIcon;
  89. }
  90.  
  91. void CCreateFileDlg::OnOk() 
  92. {
  93.     HANDLE File;  
  94.     BYTE Win9x = 0;
  95.     
  96.     __asm
  97.     {
  98.         push fs:[30h]
  99.         pop eax
  100.         test eax,eax  // o jak² operaΦnφ systΘm se jednß?
  101.         jns Not_Win9x  // skok = operaΦnφm systΘmem je Windows 9x/Me
  102.         mov byte ptr Win9x,1
  103.             
  104. Not_Win9x:
  105.     }    
  106.  
  107.     if (Win9x)
  108.         File = CreateFile( "\\\\.\\SICE",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  109.     else
  110.         File = CreateFile("\\\\.\\NTICE",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  111.  
  112.     if( File != INVALID_HANDLE_VALUE )  // byl ovladaΦ nalezen?
  113.     {
  114.         CloseHandle(File);
  115.         MessageBox("SoftICE nalezen",NULL,MB_OK);
  116.     }
  117.     else
  118.         MessageBox("SoftICE nenalezen",NULL,MB_OK);
  119. }
  120.